package models

import (
	"context"

	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/mongo/options"
)

// SaveDacSample 保存一个数据点
func SaveDacSample(dacName string, timeUnixNano int64, data float64) error {
	_, err := db.Collection("samples").UpdateOne(context.TODO(), bson.M{
		"dacName": dacName,
	}, bson.M{
		"$push": bson.M{
			"samples": bson.M{
				"timeUnixNano": timeUnixNano,
				"data":         data,
			},
		},
	}, options.Update().SetUpsert(true))
	return err
}
